from flask import Flask,render_template,jsonify,request
from flask_cors import CORS
from flask import make_response
from test import set_config,user_list,weibo_list,reply_list,forward_list,attention_list,active_list,influence_list
app = Flask(__name__)
CORS(app)

import pymysql



replys = reply_list()
forwards = forward_list()
attentions = attention_list()
influences = influence_list()
actives = active_list()


@app.route('/attention',methods=['GET'])
def get_attention_list():
    return jsonify({'attention':attentions})

@app.route('/forward',methods=['GET'])
def get_forward_list():
    return jsonify({'forward':forwards})


@app.route('/influence',methods=['GET'])
def get_influence():
    return jsonify({'influence':influences})

@app.route('/active',methods=['GET'])
def get_actives():
    return jsonify({'active':actives})

@app.route('/reply',methods=['GET'])
def get_reply_list():
    return jsonify({'rep':replys})

@app.route('/user_list',methods=['POST'])
def get_user_list():
    param = request.get_json(silent=True)
    # print(param)
    users = user_list(param)
    return jsonify({'user':users})


@app.route('/weibo_list',methods=['POST'])
def get_weibo_list():
    param = request.get_json(silent=True)
    weibo_contexts = weibo_list(param)
    return jsonify({'con':weibo_contexts})

@app.route("/config",methods=["POST"])
def setConfig():
    param = request.get_json(silent=True)
    set_config(param)
    return jsonify({'message':'配置参数保存成功！'})
    

if __name__ == "__main__":
    app.run(debug=True)